fixed spec test passed

Judy Ngai 9 年之前
父节点
当前提交
91476dc0fe
共有 2 个文件被更改,包括 9 次插入13 次删除
  1. 2 5
      app/models/agents/twitter_user_agent.rb
  2. 7 8
      spec/models/agents/twitter_user_agent_spec.rb

+ 2 - 5
app/models/agents/twitter_user_agent.rb

@@ -52,17 +52,14 @@ module Agents
52 52
         'include_retweets' => 'true',
53 53
         'exclude_replies' => 'false',
54 54
         'expected_update_period_in_days' => '2',
55
-        'choose_home_time_line' => 'false'
55
+        'choose_home_time_line' => 'true'
56 56
       }
57 57
     end
58 58
 
59 59
     def validate_options
60 60
       errors.add(:base, "expected_update_period_in_days is required") unless options['expected_update_period_in_days'].present?
61 61
       
62
-      #errors.add(:base, "username is required") unless options['choose_home_time_line'] == 'true'
63
-      if options['choose_home_time_line'].present? && %[false].include?(options['choose_home_time_line'].to_s)
64
-        errors.add(:base, "username is required")
65
-      end
62
+      errors.add(:base, "username is required") unless options['choose_home_time_line'] == 'true'
66 63
 
67 64
       if options[:include_retweets].present? && !%w[true false].include?(options[:include_retweets])
68 65
         errors.add(:base, "include_retweets must be a boolean value string (true/false)")

+ 7 - 8
spec/models/agents/twitter_user_agent_spec.rb

@@ -6,7 +6,7 @@ describe Agents::TwitterUserAgent do
6 6
     stub_request(:any, "https://api.twitter.com/1.1/statuses/home_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
7 7
 
8 8
     @opts = {
9
-      :username => "tectonic",
9
+      #:username => "tectonic",
10 10
       :include_retweets => "true",
11 11
       :exclude_replies => "false",
12 12
       :expected_update_period_in_days => "2",
@@ -43,21 +43,20 @@ describe Agents::TwitterUserAgent do
43 43
     end
44 44
   end
45 45
 
46
-  describe "#check that user timeline works" do
46
+  describe "#check that if choose time line is false then username is required" do
47 47
     before do
48
-      stub_request(:any, /tectonic/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
48
+      #stub_request(:any, '/tectonic/').to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
49
+      stub_request(:any, "https://api.twitter.com/1.1/statuses/user_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
49 50
     end
50 51
 
51
-    it "should check that event changed with timeline sets to false" do
52
+    it "should check that error messaged added if choose time line is false" do
52 53
       
53
-      opts = @opts.merge({:choose_home_time_line => "false" })
54
+      opts = @opts.merge!({:choose_home_time_line => "false" })
54 55
 
55 56
       checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => opts)
56 57
       checker.service = services(:generic)
57 58
       checker.user = users(:bob)
58
-      checker.save!
59
-
60
-      expect { checker.check }.to change { Event.count }.by(5)
59
+      expect(checker.save).to eq (checker.errors.messages[:base] == "username is required" )
61 60
     end
62 61
   end
63 62
 end